<template>
	<view v-if="webUrl">

		<web-view :src="webUrl" @message="bindmessage" @error="binderror" @load="bindload"></web-view>

	</view>
</template>
<script lang="ts" setup>
	import { onLoad, onShareAppMessage } from "@dcloudio/uni-app"
	import { ref } from "vue"
	import { hf, dxrequest, callBack } from "@/util/index.js"

	import { h5Uri2WebviewUrl } from "@/util/link.js"
	import { isDev } from "@/conf/env.js"
	import { urlToObject,getWebviewUrl } from "@/util/link";
	const webUrl = ref()
	const shareUserId = ref()
	onLoad(async (options) => {
		const jkjxcdf = getWebviewUrl()
		console.log(jkjxcdf)
		console.log(5554412)
		let params = {}
		const navigationPath = uni.getStorageSync('navigationPath')
		console.log('wbview:navigationPath', navigationPath)

		if (navigationPath) {
			params = urlToObject(navigationPath) || {}
			uni.setStorageSync('navigationPath', undefined)

		}
		const link = h5Uri2WebviewUrl(params)
		console.log('wbview:', params, link)
		if (isDev) {
			uni.showModal({
				title: 'wbview:onLoad',
				content: params && (JSON.stringify(params) + link) || '-',
				showCancel: false

			})
		}
		webUrl.value = link
	})



	const binderror = (data) => {
		console.log(data)
	}
	const bindload = (data) => {
		console.log(data)
	}

	const bindmessage = (data) => {
		console.log(data)
		let obj = data.detail.data[0]
		if (obj.action == "miniapp_task") {
			data.banping = 4
			data.token = obj.token
		}else{
			data.banping = 3
			data.miniapp_charge_path = data.miniapp_charge_path
		}
		uni.$emit('citycallback', data)
	}

onShareAppMessage(() => {
	const shareUserId = uni.getStorageSync("shareUserId")
	const initSkill = uni.getStorageSync("initSkill")

	return {
		title: '点我及进入玛雅圣殿AI体验吧',
	}
})
</script>

<style scoped>

</style>